package com.xlh.job;

import cn.hutool.core.date.DateUtil;
import com.xlh.enums.SystemConfigEnum;
import com.xlh.service.system.SystemConfigService;
import com.xlh.util.ShareCodeUtil;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

/**
 * 申请码
 * <p>
 * Created by lx on 2018/7/4.
 */
@Component
public class InvitationCodeTask {

    private final static Logger LOGGER = LoggerFactory.getLogger(InvitationCodeTask.class);

    @Autowired
    private SystemConfigService systemConfigService;

    @Scheduled(cron = "0 0 3 * * *")
    public void generateCode() {

        try {

            // 生成申请码
            String code = ShareCodeUtil.dataToString(DateUtil.today());

            // 添加/修改数据库
            systemConfigService.updateSystemConfig(SystemConfigEnum.INVITATION_CODE, code);

        } catch (Exception e) {
            LOGGER.error("生成申请码失败", e);
        }

    }

}
